package com.cyq.day24.regex;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

public class DetailFrame extends JFrame {
    private  User user=new User();
    private JPanel panel1,panel2,panel3;
    private JTextArea textArea;
    private JTextField textField1,textField2,textField3;
    private JButton button1,button2;
    private JLabel label1,label2;

    public DetailFrame()  {
    }

    public DetailFrame(ArrayList arrayList){
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setTitle("查询显示页面");
        this.setBounds(300,100,500,500);
        panel1=new JPanel();
        panel1.setLayout(new GridLayout(2,1,5,5));
        panel2=new JPanel();
        label1=new JLabel("根据id查询用户");
        textField1=new JTextField(20);
        button1=new JButton("查询");
        button1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                for (int i = 0; i <arrayList.size() ; i++) {
                    user=(User) arrayList.get(i);
                    if (textField1.getText().equals(user.getUserName())){
                        textArea.setText(user.toString());
                    }
                }
            }
        });
        panel2.add(label1);
        panel2.add(textField1);
        panel2.add(button1);
        panel3=new JPanel();
        label2=new JLabel("根据用户名查询");
        textField2=new JTextField(20);
        button2=new JButton("查询");
        button2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                for (int i = 0; i <arrayList.size() ; i++) {
                    user=(User)arrayList.get(i);
                    if (user.getUserName().contains(textField2.getText())){
                        textArea.setText(user.toString());
                    }
                }
            }
        });
        panel3.add(label2);
        panel3.add(textField2);
        panel3.add(button2);
        panel1.add(panel2);
        panel1.add(panel3);
        this.add(panel1, BorderLayout.NORTH);
        textArea=new JTextArea();
        textArea.setText(textArea.getText()+arrayList.toString()+"\n");
        this.add(textArea);
    }

}
